﻿using System;
using System.Linq;
using Xc.DataAccess.DataBase.DeviceInfos.Models;
using System.Data;

namespace Xc.DataAccess.DataBase.DeviceInfos.Extensions
{
    public static class EfExtensions
    {
        /// <summary>
        /// 在这个时间段内
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="dateTimeStart"></param>
        /// <param name="dateTimeEnd"></param>
        /// <returns></returns>
        public static IQueryable<T> Between<T>(this IQueryable<T> source, DateTime? dateTimeStart, DateTime? dateTimeEnd) where T : IDateTimeCreate
        {
            if (dateTimeStart.HasValue)
            {
                source = source.Where(p => p.DateTimeCreate > dateTimeStart);
            }
            if (dateTimeEnd.HasValue)
            {
                source = source.Where(p => p.DateTimeCreate <= dateTimeEnd);
            }
            return source;
        }
    }

}
